<template>
  <div>
    <el-dialog
      :title="formtype == 1 ? '新增组织维护' : '编辑组织维护'"
      width="460px"
      @close = 'cancel'
      :visible.sync="dialogFormVisible"
    >
      <el-form :model="form" ref="ruleForm" :rules="rulesPa" label-position="left">
        <el-form-item label="名称" prop="Name" :label-width="formLabelWidth">
          <el-input
            class="input_border_bottom"
            v-model="form.Name"
            placeholder="请输入名称"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="类型" prop="Type" :label-width="formLabelWidth">
          <el-select
          :disabled="formtype =='2'"
            class="select_border_bottom"
            v-model="form.Type"
            placeholder="请选择类型"
          >
            <el-option :label="item.label" :value="item.value" v-for="(item,index) in $optiondata.OrganType" :key='index'></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="隶属部门" prop="ParentId" v-if="form.Type=='2'" :label-width="formLabelWidth">
          <el-select
          :disabled="formtype =='2'"
            class="select_border_bottom"
            v-model="form.ParentId"
            placeholder="请选择隶属部门"
          >
            <el-option :label="item.Name" :value="item.Id" v-for="(item,index) in option" :key='index'></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="别名" prop="OtherName" :label-width="formLabelWidth">
          <el-input
            class="input_border_bottom"
            v-model="form.OtherName"
            placeholder="请输入别名"
            auto-complete="off"
          ></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="Desc" :label-width="formLabelWidth">
          <el-input
            class="textarea_border_bottom"
            v-model="form.Desc"
            type="textarea"
            placeholder="请输入描述"
            auto-complete="off"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="commit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogFormVisible: false,
      formtype: 1,
      formLabelWidth: '80px',
      rulesPa: {
          Name: [
            { required: true, message: '请输入名称', trigger: 'blur' },
          ],
          Type: [
            { required: true, message: '请选择类型', trigger: 'blur' },
          ],
          OtherName: [
            { required: true, message: '请输入别名', trigger: 'blur' },
          ],
          Desc: [
            { required: true, message: '请输入描述', trigger: 'blur' },
          ],
          ParentId: [
            { required: true, message: '请输入描述', trigger: 'blur' },
          ],
        },
      option:{},
      form: {
        Name: '',
        Type: '1',
        ParentId: '0',
        OtherName: '',
        Desc: '',
      }
    }
  },
  created() {
  },
  watch: {
    "$store.state.Humanmanage.SaveOrganization":function (data){
        if (data.Code==0) {
          this.$message({
          showClose: true,
          message: this.formtype=='1'?'添加成功':'编辑成功',
          type: 'success'
        });
        this.$parent.getOrganizationTree();
        this.$parent.getlistdata();
        this.cancel();
        }
    },
  },
  methods: {
    cancel() {
      this.form = {
        Name: '',
        Type: '1',
        ParentId: '',
        OtherName: '',
        Desc: '',
      }
      this.dialogFormVisible = false
    },
    commit() {
      this.$refs.ruleForm.validate((valid) => {
          if (valid) {
            let obj = {
                  "MN":"SaveOrganization",
                  "RequestId":1,
                  "UserId":1,
                  "DataContent":this.form
                 }
            this.MIX_send(obj);
          } else {
            return false;
          }
        });
    },
  },
}
</script>

<style lang="less" scoped>
</style>